{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4ef2e421-b92b-49fc-9933-923d3e596488",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dataclasses import dataclass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33a96887-cb0a-4428-8459-56391c4a6f2a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e2974770-f7dd-438a-aad8-0d2b7b94205f",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = [\n",
    "    {'姓名': '张三', '年龄': 18, '成绩': 85},\n",
    "    {'姓名': '李四', '年龄': 20, '成绩': 72},\n",
    "    {'姓名': '王五', '年龄': 19, '成绩': 90},\n",
    "    {'姓名': '赵六', '年龄': 22, '成绩': 55},\n",
    "    {'姓名': '孙七', '年龄': 21, '成绩': 78},\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a01e4631-e079-499b-ba0b-81de0137bde4",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = [\n",
    "    ('张三', 18, 85),\n",
    "    ('李四', 20, 72),\n",
    "    ('王五', 19, 90),\n",
    "    ('赵六', 22, 55),\n",
    "    ('孙七', 21, 78),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c86a511d-1991-4ed8-9a5a-8bca71f2d6a1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d692ed66-9b40-4e0b-b274-9057132f21dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student:\n",
    "    def __init__(self, name, age, grade):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "        self.grade = grade\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1e3e4b6d-5db5-4b03-a489-f0032d54a430",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<__main__.Student at 0x7f4d58484e20>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = Student('张三', 18, 85)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2ad49783-ed0a-4f57-976e-458e271fb564",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bed7eb2b-b4ee-4bb7-932e-230727e58578",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student:\n",
    "    def __init__(self, name, age, grade):\n",
    "        self.name = name\n",
    "        self.age = age\n",
    "        self.grade = grade\n",
    "\n",
    "    def __repr__(self):\n",
    "        return f'Student(name={repr(self.name)}, age={repr(self.age)}, grade={repr(self.grade)})'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "879842b9-ce04-4834-85bc-2484cff1e94a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Student(name='张三', age=18, grade=85)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = Student('张三', 18, 85)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6364e5d-1bc6-4a1d-9601-47de10014c6c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6d8218a1-5fb8-4052-9e62-e3356983e2d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = [\n",
    "    Student('张三', 18, 85),\n",
    "    Student('李四', 20, 72),\n",
    "    Student('王五', 19, 90),\n",
    "    Student('赵六', 22, 55),\n",
    "    Student('孙七', 21, 78),\n",
    "    Student('赵六', 22, grade=55),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f3384a7f-3df4-4bf9-9fc2-625039ef1c33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Student(name='张三', age=18, grade=85),\n",
       " Student(name='李四', age=20, grade=72),\n",
       " Student(name='王五', age=19, grade=90),\n",
       " Student(name='孙七', age=21, grade=78)]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[s for s in students if s.grade >= 60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d480b61e-7d2a-4561-bea2-7090c9be52ec",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73f8b9a8-94a5-4aa8-be2a-aed09d8c841e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1e57f49b-73ce-4078-ab55-f16d043c2a2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dataclasses import dataclass\n",
    "from decimal import Decimal\n",
    "\n",
    "@dataclass\n",
    "class Student:\n",
    "    name: str\n",
    "    age: int\n",
    "    grade: Decimal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ff320f9-b0f2-4a8c-8d22-74c3a6d06b9b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "73e3f98d-c205-4a4d-a394-644dde559c33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Student(name='张三', age=18, grade=85)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = Student('张三', 18, 85)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "338802c0-8140-4d37-be9c-c0f685773592",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "a934ce77-446a-4fbf-9476-0f3eb64ef529",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "85"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.grade"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "9234e12c-8177-4392-9332-bd3aa795804d",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = [\n",
    "    Student('张三', 18, 85),\n",
    "    Student('李四', 20, 72),\n",
    "    Student('王五', 19, 90),\n",
    "    Student('赵六', 22, 55),\n",
    "    Student('孙七', 21, 78),\n",
    "    Student('赵六', 22, 55),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "023502c2-036b-4cb6-b573-b14bfa11b395",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Student(name='张三', age=18, grade=85),\n",
       " Student(name='李四', age=20, grade=72),\n",
       " Student(name='王五', age=19, grade=90),\n",
       " Student(name='孙七', age=21, grade=78)]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[s for s in students if s.grade >= 60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fe54efd-bcd2-40e6-919f-c6d8df80b9fe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "4c74def6-7c51-4a5f-833e-8b61fb2d0358",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dataclasses import dataclass\n",
    "from decimal import Decimal\n",
    "\n",
    "@dataclass\n",
    "class 学生:\n",
    "    姓名: str\n",
    "    年龄: int\n",
    "    成绩: Decimal\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "6abfada9-81c5-4617-9495-7fb6971468ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "学生(姓名='张三', 年龄=18, 成绩=85)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = 学生('张三', 18, 85)\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "493b4d2a-b37d-4715-b37f-23af4bcbfaa9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张三'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.姓名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8af57e7-d240-42a4-843a-0709b9f0d2f8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "67be518f-8aed-4481-af4e-9f660a9a0ad0",
   "metadata": {},
   "outputs": [],
   "source": [
    "students = [\n",
    "    学生('张三', 年龄=18, 成绩=85),\n",
    "    学生('李四', 20, 72),\n",
    "    学生('王五', 19, 90),\n",
    "    学生('赵六', 22, 55),\n",
    "    学生('孙七', 21, 78),\n",
    "    学生('赵六', 22, 55),\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cb4daa9-eb14-4fc6-8328-5f6fffd86240",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "76637250-12ff-438c-8a09-f49350edd528",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[学生(姓名='张三', 年龄=18, 成绩=85),\n",
       " 学生(姓名='李四', 年龄=20, 成绩=72),\n",
       " 学生(姓名='王五', 年龄=19, 成绩=90),\n",
       " 学生(姓名='孙七', 年龄=21, 成绩=78)]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[s for s in students if s.成绩 >= 60]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a711441b-d8ec-4ddb-b338-d72217d1bb59",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
